#pragma once

#include <stdlib.h>
#include <vector>
#include <math.h>
#include <algorithm>
#include "vertex.h"
#include "MiscFunctions.h"
#include "simplexnoise1234.h"
#include <gl\glut.h>

#define HEIGHT 200
#define WIDTH 200
#define STEP 5
#define OCTAVES 4

using namespace std;

class Terrain
{
public:
	Terrain(void);
	~Terrain(void);

	enum TerrainType { DIRT, GRAVEL, ROAD, OCCUPIED };

	float map[WIDTH/STEP][HEIGHT/STEP];

	int cellCountX, cellCountY;

	void Draw();

	bool validCell(int, int);
	static vertex GetTerrainPoint(vertex position);
	static vertex GetWorldPoint(int i, int j);
	TerrainType GetTerrainType(int i, int j);
	TerrainType GetTerrainType(vertex position);
	void Occupy(vertex position);
	void Evict(vertex position);
	void Occupy(int i, int j);
	void Evict(int i, int j);
	void NextPermutation();

	void Load_Test_Map_1();
	void Load_Test_Map_2();
	void Load_Test_Map_3();

private:
	float smoothNoise[OCTAVES][WIDTH/STEP][HEIGHT/STEP];

	float GetNoise(int i, int j);
	void DrawCell(int i, int j);

	// Perlin functions
	float interpolate(float x, float y, float alpha);
	void GenerateSmoothNoise(int octave);
	void GeneratePerlinNoise();
};

